using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;

namespace ns20
{
	internal class Class165
	{
		private readonly Type type_0;

		private readonly TypeBuilder typeBuilder_0;

		[CompilerGenerated]
		private static Func<ParameterInfo, Type> func_0;

		[CompilerGenerated]
		private static Func<Type, string> func_1;

		public Class165(Type realObjectType, TypeBuilder proxyBuilder)
		{
			type_0 = realObjectType;
			typeBuilder_0 = proxyBuilder;
		}

		public void method_0(MethodInfo methodInfo_0)
		{
			if (methodInfo_0.IsGenericMethod)
			{
				methodInfo_0 = methodInfo_0.GetGenericMethodDefinition();
			}
			FieldInfo field = typeof(Class163).GetField("UnderlyingObject", BindingFlags.Instance | BindingFlags.NonPublic);
			ParameterInfo[] parameters = methodInfo_0.GetParameters();
			Type[] array = parameters.Select((ParameterInfo parameterInfo_0) => parameterInfo_0.ParameterType).ToArray();
			MethodBuilder methodBuilder = typeBuilder_0.DefineMethod(methodInfo_0.Name, MethodAttributes.Public | MethodAttributes.Virtual, methodInfo_0.ReturnType, array);
			if (methodInfo_0.IsGenericMethod)
			{
				methodBuilder.DefineGenericParameters((from type_1 in methodInfo_0.GetGenericArguments()
					select type_1.Name).ToArray());
			}
			ILGenerator iLGenerator = methodBuilder.GetILGenerator();
			smethod_2(iLGenerator, field);
			smethod_1(parameters, iLGenerator);
			method_1(methodInfo_0, array, iLGenerator);
			smethod_0(iLGenerator);
		}

		private static void smethod_0(ILGenerator ilgenerator_0)
		{
			ilgenerator_0.Emit(OpCodes.Ret);
		}

		private void method_1(MethodBase methodBase_0, Type[] type_1, ILGenerator ilgenerator_0)
		{
			MethodInfo methodInfo = method_2(methodBase_0, type_1);
			if (methodInfo == null)
			{
				throw new MissingMethodException("Unable to find method " + methodBase_0.Name + " on " + type_0.FullName);
			}
			ilgenerator_0.Emit(OpCodes.Call, methodInfo);
		}

		private MethodInfo method_2(MethodBase methodBase_0, Type[] type_1)
		{
			if (methodBase_0.IsGenericMethod)
			{
				return type_0.smethod_15(methodBase_0.Name, type_1);
			}
			return type_0.GetMethod(methodBase_0.Name, type_1);
		}

		private static void smethod_1(ICollection<ParameterInfo> icollection_0, ILGenerator ilgenerator_0)
		{
			for (int i = 1; i < icollection_0.Count + 1; i++)
			{
				ilgenerator_0.Emit(OpCodes.Ldarg, i);
			}
		}

		private static void smethod_2(ILGenerator ilgenerator_0, FieldInfo fieldInfo_0)
		{
			ilgenerator_0.Emit(OpCodes.Ldarg_0);
			ilgenerator_0.Emit(OpCodes.Ldfld, fieldInfo_0);
		}

		[CompilerGenerated]
		private static Type smethod_3(ParameterInfo parameterInfo_0)
		{
			return parameterInfo_0.ParameterType;
		}

		[CompilerGenerated]
		private static string smethod_4(Type type_1)
		{
			return type_1.Name;
		}
	}
}
